home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacPeople 2003 February 1
/
MACPEOPLE-2003-02-01.ISO.7z
/
MACPEOPLE-2003-02-01.ISO
/
ぶらりオンラインウェアの旅
/
定番ソフト
/
Jedit(OS9)
/
MacroCollectionJ.sea
/
MacroCollection-J
/
レコード
/
ート
/
スクリプト解説
< prev
next >
Wrap
Text File
|
2001-01-02
|
6KB
|
149 lines
レコードソートマクロ
programmed by Satoshi Matsumoto <satoshi@matsumoto.co.jp>
1レコードが複数パラグラフにわたるデータのソートを行います。レコードの形式は正規表現でフレキシブルに指定できます。
ーーーーーーーーーーーーーーーーーーーーーー
ソート条件指定ダイアログ(Dialog Director用)のデータ
property theSortDialog : {size:[210, 160], contents:[ツ
{class:push button, bounds:[140, 130, 200, 150], name:"OK", enabled:3}, ツ
{class:push button, bounds:[60, 130, 120, 150], name:"Cancel"}, ツ
{class:text field, bounds:[80, 10, 110, 10 + 16], name bounds:ツ
[10, 10, 75, 10 + 16], name:"キー位置:", value:"1"}, ツ
{class:pop up, name:"", bounds:[115, 8, 200, 10 + 16], name width:0, value:1, contents:ツ
"バイト目;文字目;ワード目"}, ツ
{class:check box, bounds:[10, 40, 200, 40 + 16], name:"降順", value:false}, ツ
{class:check box, bounds:[10, 60, 200, 60 + 16], name:"数値", value:false}, ツ
{class:check box, bounds:[10, 80, 200, 80 + 16], name:"大文字小文字の区別", value:true}, ツ
{class:check box, bounds:[10, 100, 200, 100 + 16], name:"全角半角の区別", value:true} ツ
], timeout after:60}
レコード境界指定ダイアログ(Dialog Director用)のデータ
property theRecordDialog : {size:[310, 100], contents:[ツ
{class:push button, bounds:[240, 70, 300, 90], name:"OK", enabled:3}, ツ
{class:push button, bounds:[160, 70, 220, 90], name:"Cancel"}, ツ
デフォルトのレコード境界は「空行"^¥r"で終わる」に指定してある
{class:text field, bounds:[10, 40, 210, 40 + 16], value:"^¥¥r"}, ツ
{class:pop up, bounds:[215, 38, 300, 40 + 16], value:2, contents:"で始まる;で終わる"}, ツ
{class:static text, bounds:[10, 10, 300, 10 + 16], contents:"レコードの特徴を正規表現で指定してください"} ツ
], timeout after:60}
tell application "Jedit4"
Jedit4を前面へ
activate
Jeditのバージョンチェック。Rev4.0.4より古いときは中止
if version < 404 then
preDialog
display dialog "Jedit4.0 Rev4.0.4 以降を使用してください" buttons {" 了解"}
postDialog
error number -128
end if
書類がなにも開いていないときは警告をだして終了
if (count document) < 1 then
preDialog
display dialog "ブロックソートする書類を先に開いてください。" buttons {" 了解"}
postDialog
error number -128
end if
ソート条件設定ダイアログを表示
preDialog
set dialogResult to (dd auto dialog theSortDialog with grayscale)
postDialog
キャンセルボタンのときは中止
if item 1 of dialogResult is false then
error number -128
end if
ソート条件を各変数に格納する
set theKeyPosition to (item 3 of dialogResult) as integer
set theKeyType to item 4 of dialogResult
set flagDescending to item 5 of dialogResult
set flagNumeric to item 6 of dialogResult
set flagCase to item 7 of dialogResult
set flagZenkaku to item 8 of dialogResult
レコード境界指定ダイアログを表示
preDialog
set dialogResult to (dd auto dialog theRecordDialog with grayscale)
postDialog
キャンセルボタンのときは中止
if item 1 of dialogResult is false then
error number -128
end if
レコード境界指定条件を各変数に格納する
set thePattern to item 3 of dialogResult
set TopOrBottom to item 4 of dialogResult
tell document 1
if length of selection < 1 then
なにも領域が選択されていないときは、全書類を対象に
set startPara to 1
set endPara to paragraph number of last character
else
選択領域の開始・終了パラグラフ番号をstartPara・startPara変数に格納
set startPara to paragraph number of selection
set endPara to paragraph number of last character of selection
end if
ソート対象データをテキスト変数theTextへ格納
set theText to paragraphs startPara thru endPara
end tell
オリジナルの書類名をtheSourceDocに格納
set theSourceDoc to name of document 1
作業用の書類名を作成しtheTempDocに格納
set theTempDoc to theSourceDoc & ".tmp"
書類名theTempDocを新規作成
make new document
set name of document 1 to theTempDoc
テキスト変数theTex(ソート対象データ)を作業用ウィンドウへコピー
insert theText at end of document theTempDoc
tell document theTempDoc
カーソルを書類の先頭へ
set startOff to 1
set selection to before byte startOff
すべてのレコード境界文字列をrepeat loop で検索する
repeat while find thePattern in it with grep without wrap around
検索した文字列をtheStringへ格納
set theString to selection
if TopOrBottom = 1 then
先頭レコード境界のときは、文字列"<RECORD>"をレコードの前に挿入する
set theString to "<RECORD>" & theString
else
終了レコード境界のときは、文字列"<RECORD>"をレコードの最後に挿入する
set theString to theString & "<RECORD>"
end if
次に検索を開始する先頭オフセットnextOffを計算
set nextOff to byteoffset of selection
set nextOff to nextOff + (length of theString)
if nextOff < (count bytes) then
書類の最後でなければ、みつかった選択領域をtheStringで置き換える
set selection to theString
カーソルを次の検索開始オフセットnextOffにセット
set selection to before byte nextOff
end if
end repeat
全てのリターンコードを文字列"<CR>"に置き換える
replace return to "<CR>" in it with grep
レコード境界マーク"<RECORD>"をリターンコードに置き換える。これで、レコードが1パラグラフになる。
replace "<RECORD>" to return in it with grep
キータイプに応じて、jsortコマンドを実行
if theKeyType is 1 then
jsort it by byte_loc key position theKeyPosition descending flagDescending numeric flagNumeric case sensitive flagCase zenkaku sensitive flagZenkaku
else if theKeyType is 2 then
jsort character_loc key position theKeyPosition descending flagDescending numeric flagNumeric case sensitive flagCase zenkaku sensitive flagZenkaku
else
jsort word_loc key position theKeyPosition descending flagDescending numeric flagNumeric case sensitive flagCase zenkaku sensitive flagZenkaku
end if
ソートのために一時リターンコードを削除
replace return to "" in it with grep
文字列"<CR>"をもとのリータンコードに復元
replace "<CR>" to return in it with grep
end tell
ソート結果を文字変数theTextへコピー
set theText to document theTempDoc
作業用ウィンドウを閉じる
close document theTempDoc saving no
tell document theSourceDoc
対象データをソート結果と入れ替える
set paragraphs startPara thru endPara to theText
ソート結果を選択表示する
set selection to paragraphs startPara thru endPara
end tell
end tell